import 'package:enjoy_plus/pages/house/components/list_item.dart';
import 'package:enjoy_plus/pages/house/room_list.dart';
import 'package:flutter/material.dart';

class BuildingList extends StatefulWidget {
  const BuildingList({super.key, required this.community});
  final String community;

  @override
  State<BuildingList> createState() => _BuildingListState();
}

class _BuildingListState extends State<BuildingList> {
  //楼栋数据
  late List<String> buildings;

  @override
  void initState() {
    super.initState();
    //随机生成楼栋数据 随机数量
    buildings = List.generate(10, (index) => '${index + 1}号楼');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('选择楼栋'),
        backgroundColor: const Color(0xFFF1F2F6),
        centerTitle: true,
        leading: IconButton(
            onPressed: () => Navigator.pop(context),
            icon: const Icon(Icons.arrow_back_ios)),
      ),
      body: Container(
        color: const Color(0xFFF1F2F6),
        child: Column(
          children: [
            ...buildings.map((building) => RoomListItem(
                room: '${widget.community} $building',
                onPressed: () {
                  Navigator.pushNamed(context, '/roomList', arguments: {
                    'community': widget.community,
                    'building': building
                  });
                })),
          ],
        ),
      ),
    );
  }
}
